package com.wxg.domain.table;

import java.util.Arrays;

import org.junit.Ignore;
import org.junit.Test;

public class TableDomainTest {

	@Test
	@Ignore
	public void testNormalArguments(){
		TableDomain td = new TableDomain();
		td.head("Name", "Age", "Msg");
		td.data("wxg", 32, "nihao");
		td.data("Jack", 23, "Hello");
		Object[][] datas = td.data();
		for(int i=0; i<datas.length; i++){
			System.out.println( String.format("%d : [%s]", i, Arrays.toString(datas[i])) );
		}
	}
	
	@Test
	@Ignore
	public void testArrayArguments(){
		TableDomain td = new TableDomain();
		td.head(new String[]{"Name", "Age", "Msg"});
		td.data(new Object[]{"wxg1", 321, "nihao1"});
		td.data(new Object[]{"Jack1", 231, "Hello1"});
		Object[][] datas = td.data();
		for(int i=0; i<datas.length; i++){
			System.out.println( String.format("%d : [%s]", i, Arrays.toString(datas[i])) );
		}
	}
	
	@Test
	@Ignore
	public void testCache(){
		System.out.println("***********");
		TableDomain td = new TableDomain();
		td.head(new String[]{"Name", "Age", "Msg"});
		td.data(new Object[]{"wxg1", 321, "nihao1"});
		td.data(new Object[]{"Jack1", 231, "Hello1"});
		Object[][] objarr = null;
		long a = System.nanoTime();
		objarr = td.data();
		System.out.printf("001耗时: %d\n", (System.nanoTime()-a));
		a = System.nanoTime();
		objarr = td.data();
		System.out.printf("002耗时: %d\n", (System.nanoTime()-a));
		td.data("Mary", 18, "welcome");
		a = System.nanoTime();
		objarr = td.data();
		System.out.printf("003耗时: %d\n", (System.nanoTime()-a));
		a = System.nanoTime();
		objarr = td.data();
		System.out.printf("003001耗时: %d\n", (System.nanoTime()-a));
		a = System.nanoTime();
		for(int i=0; i<objarr.length; i++){
			System.out.println( String.format("%d : [%s]", i, Arrays.toString(objarr[i])) );
		}
		System.out.printf("004耗时: %d\n", (System.nanoTime()-a));
		System.out.println("***********");
	}
	
	@Test
	@Ignore
	public void testRemove(){
		TableDomain td = new TableDomain();
		td.head("Name", "Age", "Msg");
		td.data("wxg", 32, "nihao");
		td.data("Jack", 23, "Hello");
		td.data("Mary", 18, "welcome");
		print(td.data());
		System.out.println("-------------");
		td.remove(1);
		print(td.data());
		System.out.println("-------------");
		td.remove(1);
		print(td.data());
		System.out.println("-------------");
	}
	
	@Test
	public void testRemoves(){
		TableDomain td = new TableDomain();
		td.head("Name", "Age", "Msg");
		td.data("wxg", 32, "nihao");
		td.data("Jack", 23, "Hello");
		td.data("Mary", 18, "welcome");
		td.data("Jack1", 231, "Hello1");
		td.data("Mary1", 181, "welcome1");
		td.data("Jack2", 232, "Hello2");
		td.data("Mary2", 182, "welcome2");
		print(td.data());
		System.out.println("-------------");
		td.removes(1,2);
		print(td.data());
		System.out.println("-------------");
		td.removes(1,2);
		print(td.data());
		System.out.println("-------------");
	}
	
	private void print(Object[][] datas){
		for(int i=0; i<datas.length; i++){
			System.out.println( String.format("%d : [%s]", i, Arrays.toString(datas[i])) );
		}
	}
	
}
